/*
@Author   : Uyynot
@Email    : uyynot@qq.com
@Time     : 2023/8/24 13:05
@File     : common.go
@Project  : web_scaff
@Desc     :
*/
package response

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

type errorResponse struct {
	Code int
	Msg  string
}
type errCode struct {
	ServerError, ParamBindError errorResponse
}

var ErrCode = errCode{
	ServerError: errorResponse{
		Code: 10101,
		Msg:  "内部服务器错误",
	},
	ParamBindError: errorResponse{
		Code: 10102,
		Msg:  "参数信息错误",
	},
}

type Response struct {
	Code int `json:"code"`
	Msg  any `json:"msg"`
	Data any `json:"data"`
}
type PageResult struct {
	List     any   `json:"list"`
	Total    int64 `json:"total"`
	Page     int   `json:"page"`
	PageSize int   `json:"pageSize"`
}

const (
	SUCCESS = iota
	ERROR
)

func Result(code int, data any, msg any, c *gin.Context) {
	c.JSON(http.StatusOK, Response{code, msg, data})
}
func Success(c *gin.Context) {
	Result(SUCCESS, nil, "success", c)
}
func Fail(c *gin.Context) {
	Result(ERROR, nil, "fail", c)
}
func FailWithMsg(msg any, c *gin.Context) {
	Result(ERROR, nil, msg, c)
}
